package com.shuchang.yygh.cmn.controller;

import com.shuchang.yygh.cmn.service.DictService;
import com.shuchang.yygh.common.result.Result;
import com.shuchang.yygh.model.cmn.Dict;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

@Api(tags = "数据字典接口")
@RestController
@RequestMapping("/admin/cmn/dict")
@CrossOrigin//跨域请求访问设置
public class DictController {

    //注入service
    @Autowired
    private DictService dictService;

    //http://localhost:8201/admin/cmn/dict/findChildData/{id}
    // 1、查询所有医院设置表信息
    @GetMapping("findChildData/{id}")
    @ApiOperation("根据数据ID查询子数局列表")
    public Result findChildData(@PathVariable Long id) {
        List<Dict> dictList = dictService.findChildData(id);
        return Result.ok(dictList);
    }

    @ApiOperation(value = "导出")
    @GetMapping(value = "/exportData")
    public Result exportData(HttpServletResponse response) {
        Boolean aBoolean = dictService.exportData(response);
        if (aBoolean) {
            return Result.ok();
        } else {
            return Result.fail();
        }
    }

    @ApiOperation(value = "导入")
    @PostMapping(value = "/importData")
    public Result importData(MultipartFile file) {
        dictService.importData(file);
//        if (dictService.importData(file)) {
            return Result.ok();
//        } else {
//            return Result.fail();
//        }
    }

}
